package main

import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/syohex/go-texttable"
"log"
)

func TestAlter() {

	db, err := sql.Open("mysql", "root:@tcp(10.90.73.139:4000)/")
	defer db.Close()

	sql := `/*--user=xes_root;--password=XueErSiroot123;--host=10.90.102.48;--port=4306;--execute=1;*/
    inception_magic_start;
    use student;
    alter table series add workcode1 varchar(10) NOT NULL DEFAULT '';
    inception_magic_commit;`

	rows, err := db.Query(sql)
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	cols, err := rows.Columns()
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(cols)

	tbl := &texttable.TextTable{}

	tbl.SetHeader(cols[0], cols[1], cols[2], cols[3], cols[4], cols[5], cols[6], cols[7], cols[8], cols[9], cols[10], cols[11])

	for rows.Next() {
		var order_id, stage, error_level, stage_status, error_message, sql, affected_rows, sequence, backup_dbname, execute_time, sqlsha1, backup_time []uint8
		err = rows.Scan(&order_id, &stage, &error_level, &stage_status, &error_message, &sql, &affected_rows, &sequence, &backup_dbname, &execute_time, &sqlsha1, &backup_time)
		tbl.AddRow(string(order_id), string(stage), string(error_level), string(stage_status), string(error_message), string(sql), string(affected_rows), string(sequence), string(backup_dbname), string(execute_time), string(sqlsha1), string(backup_time))
		// tbl.AddRow(string(nil_process(sqlsha1)))
	}
	fmt.Println(tbl.Draw())

}
